from flask_restful import Resource

from model.crud import UpdateInstance
from restful.data import  DataImage, DataText
from restful.response import ResponseSuccess
from restful.session import current_user_required,data


class Intro(Resource):
    @current_user_required
    @data(DataText())
    def post(self,data,current_user):
        current_user.intro=data['text']
        UpdateInstance(current_user)
        return ResponseSuccess(msg="成功更新个人介绍")

class Icon(Resource):
    @current_user_required
    @data(DataImage())
    def post(self,data,current_user):
        current_user.img_icon=data['image']
        UpdateInstance(current_user)

        return ResponseSuccess(msg="成功设置头像")

class Background(Resource):
    @current_user_required
    @data(DataImage())
    def post(self,data,current_user):
        current_user.img_background=data['image']
        UpdateInstance(current_user)

        return ResponseSuccess(msg="成功设置背景")

class Role(Resource):
    @current_user_required
    @data(DataText())
    def post(self,data,current_user):
        current_user.role=data['text']
        UpdateInstance(current_user)

        return ResponseSuccess(msg='成功设置角色')


